package com.kingdee.eas.custom.crm.app;

import org.apache.log4j.Logger;
import javax.ejb.*;
import java.rmi.RemoteException;
import java.sql.Timestamp;
import java.util.Date;

import com.kingdee.bos.*;
import com.kingdee.bos.util.BOSObjectType;
import com.kingdee.bos.metadata.IMetaDataPK;
import com.kingdee.bos.metadata.rule.RuleExecutor;
import com.kingdee.bos.metadata.MetaDataPK;
//import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.framework.ejb.AbstractEntityControllerBean;
import com.kingdee.bos.framework.ejb.AbstractBizControllerBean;
//import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.IObjectCollection;
import com.kingdee.bos.service.ServiceContext;
import com.kingdee.bos.service.IServiceContext;

import java.lang.String;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.eas.base.permission.UserInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.common.SysContextConstant;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.eas.framework.CoreBaseCollection;
import com.kingdee.eas.custom.crm.BusinessManageCollection;
import com.kingdee.eas.custom.crm.BusinessManageFactory;
import com.kingdee.eas.custom.crm.BusinessManageInfo;
import com.kingdee.eas.framework.SystemEnum;
import com.kingdee.eas.framework.CoreBillBaseCollection;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.framework.app.CoreBillBaseControllerBean;
import com.kingdee.eas.framework.ObjectBaseCollection;
import com.kingdee.eas.jky.enums.BusinEnum;
import com.kingdee.eas.jky.enums.CheckoutEnum;
import com.kingdee.eas.jky.enums.ClosedEnum;
import com.kingdee.eas.xr.app.XRBillStatusEnum;
import com.kingdee.util.NumericExceptionSubItem;

public class BusinessManageControllerBean extends AbstractBusinessManageControllerBean
{
    private static Logger logger =
        Logger.getLogger("com.kingdee.eas.custom.crm.app.BusinessManageControllerBean");

	protected void _close(Context ctx, IObjectValue model) throws BOSException {
//		BusinessManageInfo info = (BusinessManageInfo) model;
//		info.setCloseState(ClosedEnum.closed);
//		try {
//			_update(ctx, new ObjectUuidPK(info.getId()), info);
//		} catch (EASBizException e) {
//			e.printStackTrace();
//		}
	}

	protected void _unClose(Context ctx, IObjectValue model)
			throws BOSException {
		BusinessManageInfo info = (BusinessManageInfo) model;
		info.setCloseState(ClosedEnum.nclosed);
		info.setBusinType(BusinEnum.executing);
		try {
			_update(ctx, new ObjectUuidPK(info.getId()), info);
		} catch (EASBizException e) {
			e.printStackTrace();
		}
	}
	
	protected void _winOrders(Context ctx, IObjectValue model)
			throws BOSException {
		BusinessManageInfo info = (BusinessManageInfo) model;
		info.setBusinType(BusinEnum.winbill);
		try {
			_update(ctx, new ObjectUuidPK(info.getId()), info);
		} catch (EASBizException e) {
			e.printStackTrace();
		}
	}
	
	protected void _loseOrders(Context ctx, IObjectValue model)
			throws BOSException {
		BusinessManageInfo info = (BusinessManageInfo) model;
		info.setBusinType(BusinEnum.lostbill);
		try {
			_update(ctx, new ObjectUuidPK(info.getId()), info);
		} catch (EASBizException e) {
			e.printStackTrace();
		}
	}

	protected void _distribute(Context ctx, IObjectValue model)
			throws BOSException {
		
	}
	
	protected void _shareBusin(Context ctx, IObjectValue model)
			throws BOSException {
	}

	protected void _audit(Context ctx, IObjectValue model) throws BOSException {
		BusinessManageInfo info = (BusinessManageInfo) model;
		info.setStatus(XRBillStatusEnum.AUDITED);
		info.setBusinType(BusinEnum.executing);
		info.setAuditor((UserInfo) ctx.get(SysContextConstant.USERINFO));
		info.setAuditTime(new Date());
		try {
			BusinessManageFactory.getLocalInstance(ctx).update( new ObjectUuidPK(info.getId()), info);
		} catch (EASBizException e) {
			e.printStackTrace();
		}
	}
	public IObjectPK addnew(Context arg0, CoreBaseInfo arg1)throws BOSException, EASBizException {
		BusinessManageInfo info = (BusinessManageInfo) arg1;
		info.setCreator((UserInfo) arg0.get(SysContextConstant.USERINFO));
		info.setCreateTime(new Timestamp(System.currentTimeMillis()));
		return super.addnew(arg0, arg1);
	}

	protected void _unAudit(Context ctx, IObjectValue model)
			throws BOSException {
		BusinessManageInfo info = (BusinessManageInfo) model;
		info.setStatus(XRBillStatusEnum.TEMPORARILYSAVED);
		info.setCheckState(CheckoutEnum.unCheck);
		info.setBusinType(BusinEnum.save);
		info.setAuditTime(null);
		info.setAuditor(null);
		try {
			BusinessManageFactory.getLocalInstance(ctx).update( new ObjectUuidPK(info.getId()), info);
		} catch (EASBizException e) {
			e.printStackTrace();
		}
		
	}

	protected void _businessCheck(Context ctx, IObjectValue model)
			throws BOSException {
		
	}

}